#include <iostream>
#include <vector>
#include <memory>

// 基类
class FileHandler {
public:
    virtual void open() = 0;
    virtual void read() = 0;
    virtual void process() = 0;
    virtual void save() = 0;
    virtual ~FileHandler() {}
};

// 派生类：文本文件处理
class TextFileHandler : public FileHandler {
public:
    void open() override { std::cout << "Opening text file.\n"; }
    void read() override { std::cout << "Reading text file.\n"; }
    void process() override { std::cout << "Processing text file.\n"; }
    void save() override { std::cout << "Saving text file.\n"; }
};

// 派生类：图像文件处理
class ImageFileHandler : public FileHandler {
public:
    void open() override { std::cout << "Opening image file.\n"; }
    void read() override { std::cout << "Reading image file.\n"; }
    void process() override { std::cout << "Processing image file.\n"; }
    void save() override { std::cout << "Saving image file.\n"; }
};

// 客户端代码
int main() {
    std::vector<std::unique_ptr<FileHandler>> handlers;
    handlers.push_back(std::make_unique<TextFileHandler>());
    handlers.push_back(std::make_unique<ImageFileHandler>());

    for(auto& handler : handlers) {
        handler->open();
        handler->read();
        handler->process();
        handler->save();
    }

    return 0;
}